import React, { useEffect } from 'react';
import { Table } from 'antd';
import { getUserInfoList } from '../sysRedux/getAppList';
import { connect } from 'react-redux';

const { Column} = Table;

const columns = [
    {
      title: '用户排名',
      dataIndex: 'order',
      key: 'order',
    },
    {
      title: '用户名称',
      dataIndex: 'username',
      key: 'username',
    },
    {
      title: '用户积分',
      dataIndex: 'integral',
      key: 'integral',
    }
]

const UserInfo = (props) => {
    if (!localStorage.getItem('token')) {
        props.history.push('/');
    }
    //获取用户信息列表
    useEffect(() => {
        props.dispatch(getUserInfoList(props.match.path));
    }, []);
    let orderInfo = props.infolist;
    function sortPoints(a, b) {
        return b.integral - a.integral;
    }
    orderInfo.sort(sortPoints);
    orderInfo.map((item,idx)=>(
        item.order=idx+1
    ))
    return (
        <Table columns={columns} dataSource={orderInfo} pagination={false} bordered={false}>
        </Table>
    )
}

const mapStateToProps = (state) => ({
    infolist: state.userinfo
})

export default connect(mapStateToProps)(UserInfo);